// Tags: TopuSort
#include <algorithm>
#include <cstdio>
#include <queue>
#include <vector>

const int N = 2e3 + 5;
int n, cnt, a[N], in[N];
bool vis[N];
std::vector<int> E[N];

struct mcmp {
  inline bool operator()(const int &lhs, const int &rhs) {
    return a[lhs] < a[rhs];
  }
};
std::priority_queue<int, std::vector<int>, mcmp> pq;

struct Graph {
  int e_cnt, heads[N];
  struct Edge {
    int v, nxt;
  };
  Edge e[N * N << 1];
  inline void add(int u, int v) {
    e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
  }
} G;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void dfs(int u) {
  vis[u] = true;
  std::sort(E[u].begin(), E[u].end());
  for (auto &iter : E[u]) {
    if (!vis[iter]) {
      G.add(u, iter);
      ++in[iter];
      dfs(iter);
    }
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("AT2306 [AGC010E] Rearranging.in", "r", stdin);
  freopen("AT2306 [AGC010E] Rearranging.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); }
  std::sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      if (gcd(a[i], a[j]) != 1) E[i].push_back(j), E[j].push_back(i);

  for (int i = 1; i <= n; ++i)
    if (!vis[i]) dfs(i);

  for (int i = 1; i <= n; ++i)
    if (!in[i]) pq.push(i);

  while (!pq.empty()) {
    int u = pq.top();
    printf("%d ", a[u]);
    pq.pop();
    for (int i = G.heads[u]; i; i = G.e[i].nxt) { pq.push(G.e[i].v); }
  }
  return 0;
}